package com.hzhc.controller.baseinfo;


import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.CntrYard;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.CntrYardService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.CntrYardVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 场箱位 前端控制器
 * </p>
 *
 * @author 功不唐捐
 * @since 2024-05-23
 */
@RestController
@RequestMapping("/cntrYard")
@RequiredArgsConstructor
public class CntrYardController extends BaseController {

    private final CntrYardService yardService;

    /**
     * 场箱位 list
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getCntrYardList")
    @ResponseBody
    public ResultUtil<List<CntrYardVo>> getCntrYardList(HttpServletRequest request, @RequestBody CntrYardVo vo){
        Page<CntrYardVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<CntrYardVo> list = yardService.getCntrYardList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 场箱位 add
     * @param request
     * @param yard
     * @return
     */
    @PostMapping("/addCntrYard")
    @SysTemLog(operModul = "堆场管理-场箱位维护",operType = "ADD",operDesc = "场箱位添加",modular="PC")
    public ResultUtil<T> addCntrYard(HttpServletRequest request, @RequestBody CntrYard yard) {
        Long userID = TokenUtil.getUserID(request);
        yard.setCreateTime(LocalDateTime.now());
        yard.setUserId(userID);
        return yardService.addCntrYard(yard);
    }

    /**
     * 场箱位 update
     * @param request
     * @param yard
     * @return
     */
    @PostMapping("/updateCntrYard")
    @SysTemLog(operModul = "堆场管理-场箱位维护",operType = "UPDATE",operDesc = "场箱位修改",modular="PC")
    public ResultUtil<T> updateCntrYard(HttpServletRequest request,@RequestBody CntrYard yard){
        Long userID = TokenUtil.getUserID(request);
        yard.setUpdateTime(LocalDateTime.now());
        yard.setUpdateUserId(userID);
        return yardService.updateCntrYard(yard);
    }

    /**
     * 场箱位 delete
     * @param id
     * @return
     */
    @GetMapping("/delCntrYard/{id}")
    @SysTemLog(operModul = "堆场管理-场箱位维护",operType = "DELETE",operDesc = "场箱位删除",modular="PC")
    public ResultUtil<T> delCntrYard(@PathVariable Long id){
        return yardService.delCntrYard(id);
    }

    /**
     * 获取堆存区域
     * @return
     */
    @RequestMapping("/getYardArea")
    public ResultUtil<List<JSONObject>> getYardArea() {
        return yardService.getYardArea();
    }

}
